package ovt;

import java.util.HashMap;

import org.apache.log4j.Logger;

public class HashLogic {
	static HashMap<Integer, String> hm = new HashMap<Integer, String>();
	static HashMap<Integer, Integer> hmdirectory = new HashMap<Integer, Integer>();
	private static Logger logger = Logger.getLogger(HashLogic.class);

	public static int StringHash(String str) {// 第一级hash
		int hashcode;
		hashcode = str.hashCode() % 10;
		while (hashcode < 0)
			hashcode += 10;
		return hashcode;
	}

	public static int RSHash(String str) {// 第二级hash
		int b = 378551;
		int a = 63689;
		long hash = 0;
		for (int i = 0; i < str.length(); i++) {
			hash = hash * a + str.charAt(i);
			a = a * b;
		}
		int hashcode = (int) (hash % 10);
		while (hashcode < 0)
			hashcode += 10;
		return hashcode;
	}

	public static void main(String[] args) {
		hm.put(1, "a");
		hm.put(2, "b");
		hm.put(3, "c");
		hm.put(4, "d");
		hm.put(5, "e");
		hm.put(6, "f");
		hm.put(7, "g");
		hm.put(8, "h");
		hm.put(9, "i");
		hm.put(10, "j");
		hm.put(11, "k");
		hm.put(12, "l");
		hm.put(13, "m");
		hm.put(14, "n");
		hm.put(15, "o");
		hm.put(16, "p");
		hm.put(17, "q");
		hm.put(18, "r");
		hm.put(19, "s");
		hm.put(20, "t");
		hm.put(21, "u");
		hm.put(22, "v");
		hm.put(23, "w");
		hm.put(24, "x");
		hm.put(25, "y");
		hm.put(26, "z");
		int index = 0;
		while (index < 10000) {
			index++;
			int length = 1 + (int) (Math.random() * 100);
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < length; i++) {
				int charkey = 1 + (int) (Math.random() * 25);
				sb.append(hm.get(new Integer(charkey)));
			}
			int hashcode = RSHash(sb.toString());
			// System.out.println("生成的文件名字为："+sb.toString());
			// System.out.println("定位到文件夹："+hashcode);
			if (hmdirectory.containsKey(new Integer(hashcode))) {
				int temp = hmdirectory.get(new Integer(hashcode));
				temp++;
				hmdirectory.put(new Integer(hashcode), temp);
			} else {
				hmdirectory.put(new Integer(hashcode), 1);
			}
		}
		System.out.println();
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
		// System.out.println(1 + (int) (Math.random() * 25));
	}
}
